<template>
  <div>
    <el-form ref="form" :model="form" label-width="120px" style="width: 650px">
      <el-form-item label="管理员姓名" prop="user_name">
        <el-input type="text" v-model="form.user_sex"></el-input>
      </el-form-item>
      <el-form-item label="性别" prop="user_sex">
        <template>
          <el-radio v-model="form.user_sex" label="1">男</el-radio>
          <el-radio v-model="form.user_sex" label="0">女</el-radio>
        </template>
      </el-form-item>
      <el-form-item label="联系电话" prop="user_phone">
        <el-input type="text" v-model="form.user_phone"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="adduser">新增用户</el-button>
        <el-button @click="resetform">重置</el-button>
        <el-button @click="cancel">取消返回</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import myaxios from "@/http/MyAxios";

import httpApi from "@/http";

export default {
  data() {
    return {
      form: {
        user_name: "",
        user_sex: "",
        studytype: [],
        user_phone: "",
        License_type: [],

        city_name: "",
      },
    };
  },
  methods: {
    resetform() {
      this.form.user_name = "";
      this.form.user_sex = "";
      this.form.studytype = [];
      this.form.user_phone = "";
      this.form.License_type = [];
      this.form.city_name = "";
    },
    cancel() {
      this.$router.push("/home/admin-list");
    },
    adduser() {
      this.form.License_type = this.form.License_type.join("/");

      this.$refs["form"].validate((valid) => {
        if (valid) {
          httpApi.userApi.add(this.form).then((res) => {
            console.log("用户添加", res);
            if (res.data.code == 200) {
              this.$message.success("用户添加成功");
              this.$router.push("/home/admin-list");
            } else {
              this.$message.error("添加失败请检查");
              this.form.License_type = this.form.License_type.split("/");
            }
          });
        }
      });
    },
  },
  mounted() {},
};
</script>

<style lang="scss" scoped>
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 150px;
  height: 150px;
  line-height: 150px;
  text-align: center;
}
.avatar {
  width: 150px;
  height: 150px;
  display: block;
}
</style>